package com.thunbu.thunbu_meeting_system.viewMdel

import androidx.lifecycle.MutableLiveData
import com.hjq.toast.ToastUtils
import com.thunbu.lib_common.base.CoroutineViewModel
import com.thunbu.lib_common.utils.rsa.Base64
import com.thunbu.thunbu_meeting_system.await
import com.thunbu.thunbu_meeting_system.bean.CompanyInfo
import com.thunbu.thunbu_meeting_system.bean.UserInfo
import com.thunbu.thunbu_meeting_system.launch
import com.thunbu.thunbu_meeting_system.service.ApiService
import com.thunbu.thunbu_meeting_system.service.MainNet


/**
 * @Description:
 * @author: fancl
 * @Date: 2023/3/16 21:26
 */
class LoginViewModel : CoroutineViewModel<Unit>() {
    var userInfo = MutableLiveData<UserInfo>()
    var companysInfo = MutableLiveData<List<CompanyInfo>>()

    override fun initModel() {

    }

    fun doLogin(account: String, pwd: String,code:String) {
        launch({
            val result = MainNet.server(ApiService::class.java)
                .doLogin(account, Base64.encode(pwd.toByteArray()),code).await(true, true)
            userInfo.value = result.data
        })
    }

    fun getCompanys(account: String) {
        launch({
            val result = MainNet.server(ApiService::class.java)
                    .getCompanys(account).await(true, true)
            companysInfo.value = result.data
        })
    }
}